#!/usr/bin/env python
# encoding: utf-8

import os 
import subprocess

def main(env):
	cwd = os.path.expanduser(env["prefs"]["cwConsole_currentWorkingDirectory"])
	cmd = env["context"]["selection"].encode(env["prefs"]["cwConsole_encoding"])
	process = subprocess.Popen(cmd,shell=True,cwd=cwd,stdout=subprocess.PIPE)
	(output,error) = process.communicate()
	return [("append","\n"+output.decode(env["prefs"]["cwConsole_encoding"]))]
